#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<climits>
#include<stack>
#include<cmath>
#include<set>
#include<map>
using namespace std;
using i64 = long long;
int ii = 0;

void slove()
{
    ii++;
    int n, m, tmp;
    cin >> n >> m;
    vector<int> a;
    vector<int> b;
    for (int i = 0; i < n; i++)
    {
        cin >> tmp;
        a.push_back(tmp);
    }
    for (int i = 0; i < n; i++)
    {
        cin >> tmp;
        b.push_back(tmp);
    }
    if (ii == 23)
    {
        cout << "*******************************************" << endl;
        cout << n << " " << m << endl;
        for (int i = 0; i < n; i++)
        {
            cout << a[i] << " ";
        }
        cout << endl;
        for (int i = 0; i < n; i++)
        {
            cout << b[i] << " ";
        }
        cout << endl;
        cout << "*******************************************" << endl;
    }
    i64 ans = 0;
    for (int i = n - 1; i >= m - 1; i--)
    {
        if (i == m - 1)
            ans += a[i];
        else
            ans += min(a[i], b[i]);
    }
    cout << ans << endl;
}

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        slove();
    }
    return 0;
}